<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>简单的图形计算器</title>
        <style media="screen">
            ul.main:after {
                clear: both;
                content: "";
                display: block;
                visibility: hidden;
            }
            .main li {
                float: left;
                list-style: none;
                padding: 0 10px;
            }
            a,a:visited,a:focus {
                color: #000;
                text-decoration: none;
            }
            a:hover {
                text-decoration: underline;
            }
        </style>
    </head>
    <body>
        <h1>简单的图形计算器</h1>
        <ul class="main">
            <li><a href="main.php?action=rect">矩形</a></li>
            <li><a href="main.php?action=triangle">三角形</a></li>
            <li><a href="main.php?action=round">圆形</a></li>
        </ul>

            <?php
                // 设置自动加载这个程序需要的类文件
                error_reporting(E_ALL & ~E_NOTICE);
                function __autoload ($classname) {
                    include strtolower($classname).".class.php";
                }
                if(!empty($_GET['action'])) {
                    // 第一步：创建形状的对象
                    $classname = ucfirst($_GET['action']);
                    // echo $classname;
                    $shape = new $classname($_POST);
                    // 显示界面
                    $shape -> window();
                    // 提交后的验证
                    if(isset($_POST['dosubmit'])) {
                        //第四步：查看用户输出的数据是否正确, 失败则提示
                        if($shape->verify($_POST)) {
                            //计算图形的周长和面积
                            // $shape->area()
                            echo "周长为：".$shape->girth()."<br>";
                            echo "面积为：".$shape->area()."<br>";
                        }
                    }
                } else {
                    echo "请选择一个图形计算";
                }
             ?>

    </body>
</html>
